layui.use(['laydate','upload','layer','form'],function (){

    var form = layui.form;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var layer = layui.layer;

    laydate.render({
        elem: '#js'
    });

    //修改图片
    var uploadInst = upload.render({
        elem: '#upload1', //绑定元素
        url: '/YltUpload', //上传接口
        accept:'images'
        ,acceptMime:'image/jpg|image/png',
        before: function(obj){
            //预读本地文件示例
            obj.preview(function(index, files, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        },
        done: function(res){
            console.log(res.data.path);
            //如果上传失败
            if(res){
                //上传成功
                layer.alert("上传成功"+res.data.path);
                document.getElementById("pic").value = res.data.path;
                $("#imgDiv").css("display","")// 显示图片框
                $("input[name='carouselImg']").val(res.data.path)
            } else {
                return layer.msg('上传失败');
            }
        },
        error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });

    //表单修改
    form.on('submit(formDemo)', function (data) {
        console.log(data)

        $.ajax({
            type:'get',
            url:'/carousel/update',
            data:data.field,
            dataType:'json',
            success:function(){

                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);

                parent.resta();
            }
        })
    })







})

$('#refresh').click(function (){
    location.reload();
});